# utils/azure_openai.py

import os
import requests
from dotenv import load_dotenv
from langchain_openai import AzureChatOpenAI, AzureOpenAIEmbeddings
from langchain_openai import AzureOpenAIEmbeddings
from langchain_community.embeddings import OllamaEmbeddings

from promptAdmin.prompt_app.LLM.base import LlmBase

load_dotenv()  # 加载.env文件

# class AzureOpenAIClient:
#     def __init__(self):
#         self.api_key = os.getenv('AZURE_OPENAI_API_KEY')

class AzureOpenai(LlmBase):
    def get_model(self):
        # llm_model = AzureChatOpenAI(
        #     openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],
        #     azure_deployment=os.environ["AZURE_DEPLOYMENT_GPT"],
        #     openai_api_key=os.environ["AZURE_OPENAI_API_KEY"],
        #     openai_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"]
        # )
        # return llm_model

        os.environ["AZURE_OPENAI_API_KEY"] = os.getenv("AZURE_OPENAI_API_KEY")
        os.environ["AZURE_OPENAI_ENDPOINT"] = os.getenv("AZURE_OPENAI_ENDPOINT")
        os.environ["AZURE_OPENAI_API_VERSION"] = os.getenv("AZURE_OPENAI_API_VERSION")
        os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"] = os.getenv("AZURE_DEPLOYMENT_GPT")
        llm_model = AzureChatOpenAI(
            openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],
            azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"],
        )
        return llm_model

    def get_embedding(self):
        return AzureOpenAIEmbeddings(
            azure_deployment="Testembedding",
            openai_api_version="2023-06-01-preview",
            api_key=os.environ["AZURE_OPENAI_API_KEY"],
            azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
        )

